 format short e
 n = 500;
 
 A = randn(n); f = randn(n,1);
 
 m = 20; k = 6;


%
%   uncomment one and only one of the following selections
%
 
  which = 'LR';              % select largest real part
 
% which = 'SR';              % select smallest real part
 
% which = 'LM';              % select largest magnitude
 
% A = A+A'; which = 'LA';    % select largest algebraic
 
% A = A+A'; which = 'SA';    % select smallest algebraic
 
 tic,
 t = eig(A);
 timeA = toc

 tic
%[V,R,ritz] = Iram1(A,which,k,m,f); 
 [V,R,ritz] = Iram(A,which,k,m,f); 
 timeR = toc

 Resid__Ritz = [norm(A*V - V*R) norm(ritz)]
 tr = eig(R); k1 = length(tr);

%
      switch which

      case {'LR', 'LA'} %   sort for largest real part 
%
         [s,ii] = sort(-real(t)); t = t(ii);     
         [s,ii] = sort(-real(tr)); tr = tr(ii);     


      case {'SR', 'SA'} %   sort for smallest real part 
%
         [s,ii] = sort(real(t)); t = t(ii);     
         [s,ii] = sort(real(tr)); tr = tr(ii);     


      case {'LM'}       %   sort for largest magnitude 
%
          [s,ii] = sort(-abs(t)); t = t(ii);     
          [s,ii] = sort(-abs(tr)); tr = tr(ii);     

      end

 eigA__eigR__diff = [ t(1:k1) tr abs(abs(t(1:k1)) - abs(tr))]


